<admintpl file="header"/>
</head>
<body>
<style>
	.js-add {
			display: block;
    		width: 100px;
  			  height: 20px;
    		margin: 0 auto;
   		 margin-bottom: 20px;
	}
	.js-bottom-btn {
		width:200px;
		height:40px;
		margin:0 auto;
		
	
	}
	.js-bottom-btn  .mr {
			margin-left :100px
	}
	.well {
			padding-bottom: 0px;
	
	}
	.t-center {
		width: 564px;
		margin:0 auto;
		
	}

</style>
<div class="wrap js-check-wrap">
	<if condition="$show_type eq 1">
    <ul class="nav nav-tabs">
        <li class="active"><a href="{:U('Admin/Resources/resource_library')}">资源池管理</a></li>
    </ul>
	</if>
	
    <form class="well form-search" id="query_form" method="post" action="{:U('Admin/Resources/resource_library')}">
      <if condition="$show_type eq 2"><a href='javascript:;' onclick="add_resource(2)" class="btn btn-primary  js-add" >上传资源</a><else/><a href='javascript:;' onclick="add_resource(1)" class="btn btn-primary  js-add" >上传资源</a></if>
    <div class="t-center">
    		 资源搜索：<input type="text" name="Name" style="width: 120px;" value="{$formParam.Name}" placeholder="请输入关键字...">
        类型：
        <select name="type" style="width:100px;">
        	<option value="1" <?php if($formParam['type']==1) echo("selected");?>>图片</option>
        	<option value="2" <?php if($formParam['type']==2) echo("selected");?>>视频</option>
        	<input type="hidden" name = "before_type"  id="before_type" value="<?php echo $before_type ? $before_type : $formParam['type'];?>">
        	<input type="hidden" name = "call_back"  id="call_back" value="<?php echo $call_back;?>">
        	<!-- 记录页面重新加载之前的type,以便判断是否加载循环保存的resouce_ids -->
        </select>
        <?php if($formParam['type'] == '1'){?>
        水印：
        <select name="is_water" style="width:70px;">
        	<option value="" >全部</option>
        	<option value="0" <?php if($formParam['is_water']=='0') echo("selected");?>>否</option>
        	<option value="1" <?php if($formParam['is_water']=='1') echo("selected");?>>是</option>
        </select>
       <?php }?> 
        <!-- 起始：<input type="text" name="startDate" style="width: 120px;" value="{$formParam.startDate}" placeholder="">
        结束：<input type="text" name="endDate" style="width: 120px;" value="{$formParam.endDate}" placeholder=""> -->
        <input type="button" name="query_form_btn" id="queryBtn" data-action="{:U('Admin/Resources/resource_library')}"  class="btn btn-primary" value="查询"/>
        
        
        <input type="hidden" name="fileDir" id="fileDir" value="<?php echo time().rand();?>">
        <input type="hidden" class = 'order' name="order" value="{$formParam.order}">
        <input type="hidden"  name="show_type" value="{$show_type}">
        <input type="hidden"  name="chosed_resource_ids" value="">
        <br/><br/>
    </div>
  
       
    </form>
    
    <!-- 显示图片和视频层开始 -->
  
    	
	 <style>
	 	.span77 {
			position: relative;
		}
		.btn-file {
			position: absolute;
			top: 0;
			left: 0;
			width: 56px!important;
			height: 20px!important;
			padding: 7px 20px;
			z-index: 3;
			opacity: 0;
			cursor: pointer;
		}
	 	.clearfix:after {
	 		height: 0;
	 		content: "\200B";
	 		clear: both;
	 		display: block;
	 	}
	 	.clearfix {
	 		*zoom: 1;
	 	}
		 ul, li {
		 	list-style: none;
		 }
		 #to_top_prompt_info li  {
	 		float: left;
	 		margin-right: 10px;
	 		margin-bottom: 10px;
	 	}
	 	#to_top_prompt_info img {
	 		display: block;
	 		width: 100px;
	 		height: 60px;
	 	}
	 	#to_top_prompt_info span {
	 		width: 100%;
	 		display: block;
	 		text-align: center;
	 		padding: 4px 0;
	 	}
	 	#page_show {
	 		height: 30px;
   			 line-height: 30px;
	 	}
	 	#page_show a{padding: 4px 6px!important}
	 	.ajaxify:last-child {
	 		margin-right:20px;
	 	}
	 	#layui-layer-iframe1 {
	 			height:600px !important;
	 	}
	 	.fn {
	 		float:none !important;
	 	}
	 	</style>
	 	
	 	<!-- <foreach name="all_data" item="all_vo">
	 		<input type="hidden" id="thumbnail_url_{$all_vo.resource_id}" value="{$all_vo.thumbnail_url}">
	 		<input type="hidden" id="file_id_{$all_vo.resource_id}" value="{$all_vo.file_id}">
	        <input type="hidden" id="file_name_{$all_vo.resource_id}" value="{$all_vo.file_name}">
	        <input type="hidden" id="url_{$all_vo.resource_id}" value="{$all_vo.url}">
	        <input type="hidden" id="url1_{$all_vo.resource_id}" value="{$all_vo.url1}">
	        <input type="hidden" id="url2_{$all_vo.resource_id}" value="{$all_vo.url2}">
	        <input type="hidden" id="duration_{$all_vo.resource_id}" value="{$all_vo.duration}">
	        <input type="hidden" id="size_{$all_vo.resource_id}" value="{$all_vo.size}">
	        <input type="hidden" id="size1_{$all_vo.resource_id}" value="{$all_vo.size1}">
	        <input type="hidden" id="size2_{$all_vo.resource_id}" value="{$all_vo.size2}">
	        <input type="hidden" id="height_{$all_vo.resource_id}" value="{$all_vo.height}">
	        <input type="hidden" id="height1_{$all_vo.resource_id}" value="{$all_vo.height1}">
	        <input type="hidden" id="height2_{$all_vo.resource_id}" value="{$all_vo.height2}">
	        <input type="hidden" id="width_{$all_vo.resource_id}" value="{$all_vo.width}">
	        <input type="hidden" id="width1_{$all_vo.resource_id}" value="{$all_vo.width1}">
	        <input type="hidden" id="width2_{$all_vo.resource_id}" value="{$all_vo.width2}">
	 	</foreach>
	 	 -->
    <!-- 显示图片和视频层结束 -->
    
    
    <div id="ajax_show">
    <form id="data_form" class="js-ajax-form" action="{:U('Admin/Resources/resource_library')}" method="post">
        <table class="table table-hover table-bordered">
            <thead>
            <tr>
                <th>序号</th>
                <th>名称</th>
                <th>类型</th>
                <?php if($formParam['type'] == '1'){?>
                	<th>是否水印</th>
                <?php }?>
                <th>
                	上传时间&nbsp;
                	<a href="javascript:;" onclick="data_sort('asc')" title="升序">↑</a>&nbsp;&nbsp;<a href="javascript:;" onclick="data_sort('desc')" title="倒序">↓</a>
                	<input type="hidden" name="Name" value="{$formParam.Name}">
                	<input type="hidden" name="startDate" value="{$formParam.startDate}">
                	<input type="hidden" name="endDate" value="{$formParam.endDate}">
                	<input type="hidden" name="type" value="{$formParam.type}">
                	<input type="hidden" class = 'order' name="order" value="{$formParam.order}">
                	<input type="hidden"  name="show_type" value="{$show_type}">
                	<input type="hidden"  name="chosed_resource_ids" value="">
                </th>
                <th>上传者</th>
                <if condition="$show_type eq 2"><th>操作</th></if>
            </tr>
            </thead>
            <tbody>
            <!--<if condition="($vo['type'] eq 2 and $vo['status'] eq 2) or in_array($vo['type'],array(1,3)) or $show_type eq 1">  -->
            <!-- </if> -->
            <?php $tmp_key = 1;?>
            <foreach name="data" item="vo">
                <tr>
                    <td><?php echo $tmp_key;?></td>
                    <td>{$vo.file_name}</td>
                    <td>
                    	<if condition="$vo['type'] eq 1">图片</if>
                    	<if condition="$vo['type'] eq 2">视频</if>
                    	<if condition="$vo['type'] eq 3">附件</if>
                    </td>
                    <?php if($formParam['type'] == '1'){?>
                    	<td>
	                    	<if condition="$vo['is_water'] eq 1">
	                    	是
	                    		<else/>
	                    	否
	                    	</if>
                		</td>
                	<?php }?>
                    <td>
                    	<if condition="$vo['type'] eq 2 and $vo['status'] eq 1"> 转码中
						<elseif condition="$vo['type'] eq 2 and $vo['status'] eq 3"/>转码失败
						<else /> {$vo.create_time}
						</if>
                    </td>
                    <td>
                    	{$vo.operation_name}
                    </td>
                    <if condition="$show_type eq 2">
	                    <td>
	                    <if condition="$vo['type'] eq 2 and $vo['status'] eq 1">
	                    <else/>
	                    	    <input id="checkbox_<?php echo $vo['resource_id'];?>" type="checkbox" name="checkbox[]" <?php if(in_array($vo['resource_id'],$chosed_resource_ids_arr)) echo "checked=checked;"?>  onclick="set_resource('{$vo.resource_id}','{$vo.type}');">
	                    </if>
	                    <!-- <?php if(in_array($vo['resource_id'],$chosed_resource_ids_arr)) echo "checked=checked;"?> -->

	                    </td>
                    </if>
                </tr>
                <?php $tmp_key++;?>
                
                     <input type="hidden" id="thumbnail_url_{$vo.resource_id}" value="{$vo.thumbnail_url}">
			 		<input type="hidden" id="file_id_{$vo.resource_id}" value="{$vo.file_id}">
			        <input type="hidden" id="file_name_{$vo.resource_id}" value="{$vo.file_name}">
			        <input type="hidden" id="url_{$vo.resource_id}" value="{$vo.url}">
			        <input type="hidden" id="url1_{$vo.resource_id}" value="{$vo.url1}">
			        <input type="hidden" id="url2_{$vo.resource_id}" value="{$vo.url2}">
			        <input type="hidden" id="duration_{$vo.resource_id}" value="{$vo.duration}">
			        <input type="hidden" id="size_{$vo.resource_id}" value="{$vo.size}">
			        <input type="hidden" id="size1_{$vo.resource_id}" value="{$vo.size1}">
			        <input type="hidden" id="size2_{$vo.resource_id}" value="{$vo.size2}">
			        <input type="hidden" id="height_{$vo.resource_id}" value="{$vo.height}">
			        <input type="hidden" id="height1_{$vo.resource_id}" value="{$vo.height1}">
			        <input type="hidden" id="height2_{$vo.resource_id}" value="{$vo.height2}">
			        <input type="hidden" id="width_{$vo.resource_id}" value="{$vo.width}">
			        <input type="hidden" id="width1_{$vo.resource_id}" value="{$vo.width1}">
			        <input type="hidden" id="width2_{$vo.resource_id}" value="{$vo.width2}">
			        
            </foreach>
            </tbody>
        </table>        
    </form>
    </div>
     <input type="hidden" id="chosed_video_ids" value="">
	<input type="hidden" id="chosed_video_names" value="">
	<input type="hidden" id="chosed_video_urls" value="">
	<input type="hidden" id="chosed_video_thumbnail_urls" value="">
	<input type="hidden" id="chosed_img_ids" value="">
	<input type="hidden" id="chosed_img_names" value="">
	<input type="hidden" id="chosed_img_urls" value="">
	<input type="hidden" id="chosed_video_file_ids" value="">
	<input type="hidden" id="chosed_video_durations" value="">
	<input type="hidden" id="chosed_video_heights" value="">
	<input type="hidden" id="chosed_video_widths" value="">
	<input type="hidden" id="chosed_video_sizes" value="">
    <div class="pagination" id="page_show">{$page}</div>
    <div id="prompt_msg">
	 		<div id="user_speak_content_box"> 
	 			<div id="to_top_prompt_info">
	 				<ul class="clearfix" id="upload_img_show">
	 				</ul>
	 			</div>
	 		</div>
	 </div>
	   <div class="span77 fn" id="chose_video_show"></div>
	   <div class="span77" id="transcoding_videos_show"></div>
    <div class="js-bottom-btn ">
    		<if condition="$show_type eq 2"><button  class="btn btn-primary  js-button"  id="resource_submit">确认</button></if>
    		<if condition="$show_type eq 2"><button  class="btn btn-primary  js-button mr  layui-layer-close"  id="cancel_submit">取消</button></if>
    </div>
  
</div>
<script src="__PUBLIC__/js/common.js"></script>
<script src="__PUBLIC__/js/publish.js"></script>
<script src="__PUBLIC__/js/layer/layer.js"></script>
<script type="text/javascript" src="__PUBLIC__/js/content_addtop.js"></script>
<script type="text/javascript">
    //编辑器路径定义
var editorURL = GV.DIMAUB;
</script>
<script type="text/javascript" src="__PUBLIC__/js/ueditor/ueditor.config.js"></script>
<script type="text/javascript" src="__PUBLIC__/js/ueditor/ueditor.all.min.js"></script>
<script type="text/javascript" >
$(function(){
	//console.log(window.localStorage);
	var chosed_resource_ids = window.localStorage.chosed_resource_ids;
	var before_type = $("#before_type").val();
	var now_type = "<?php echo $formParam['type'];?>";
	if(before_type == now_type){
		if(now_type == '1'){
			var chosed_img_ids = window.localStorage.chosed_img_ids;
			if(chosed_img_ids){
				chosed_img_ids_arr = chosed_img_ids.split(',');
				chosed_img_ids_arr.pop();
				var chosed_img_names = window.localStorage.chosed_img_names;
				chosed_img_names_arr = chosed_img_names.split(',');
				var chosed_img_urls = window.localStorage.chosed_img_urls;
				chosed_img_urls_arr = chosed_img_urls.split('~');
				
				
				var show_img_html = '';
				for (var i=0;i<chosed_img_ids_arr.length;i++)
				{
					show_img_html +='<li><img src="'+chosed_img_urls_arr[i]+'" alt="" /><span><a href="javascript:;" onclick="DelImages('+"'"+chosed_img_ids_arr[i]+"'"+')" class="del_btn">删除</a></span></li>';
					$("#checkbox_"+chosed_img_ids_arr[i]).attr("checked",true);
				}
				$("#upload_img_show").html(show_img_html);
				$("#chosed_img_ids").val(chosed_img_ids);
				$("#chosed_img_names").val(chosed_img_names);
				$("#chosed_img_urls").val(chosed_img_urls);
				$("input[name='chosed_resource_ids']").val(chosed_resource_ids);
			}
		}
		
		
		if(now_type == '2'){
			var transcoding_videos_name = "<?php echo $transcoding_videos_name;?>";
			transcoding_videos_name_arr = transcoding_videos_name.split(',');
			transcoding_videos_name_arr.pop();
			var transcoding_videos_html = '';
			for(i = 0; i< transcoding_videos_name_arr.length; i++){
				if(transcoding_videos_name_arr[i]){
					transcoding_videos_html +='<li>视频:'+transcoding_videos_name_arr[i]+'     正在转码中</li></br>';
				}
			}
			$("#transcoding_videos_show").html(transcoding_videos_html);
		}
	}else{
		$("#before_type").val(now_type);
	}
	
	
	//
	/*var chosed_resource_ids = "<?php echo $chosed_resource_ids;?>";
	var before_type = $("#before_type").val();
	var now_type = "<?php echo $formParam['type'];?>";
	if(before_type == now_type){
		chosed_resource_ids_arr = chosed_resource_ids.split(',');
		chosed_resource_ids_arr.pop();
		for(i = 0; i< chosed_resource_ids_arr.length; i++){
			if(chosed_resource_ids_arr[i]){
				set_resource(chosed_resource_ids_arr[i],now_type);
			}
			//$("#checkbox_"+chosed_resource_ids_arr[i]).click();
		}
		
		if(now_type == '2'){
			var transcoding_videos_name = "<?php echo $transcoding_videos_name;?>";
			transcoding_videos_name_arr = transcoding_videos_name.split(',');
			transcoding_videos_name_arr.pop();
			var transcoding_videos_html = '';
			for(i = 0; i< transcoding_videos_name_arr.length; i++){
				if(transcoding_videos_name_arr[i]){
					transcoding_videos_html +='<li>视频:'+transcoding_videos_name_arr[i]+'     正在转码中</li></br>';
				}
			}
			$("#transcoding_videos_show").html(transcoding_videos_html);
		}
	}else{
		$("#before_type").val(now_type);
	}*/
})

function show(id){
	//user函数名 一定要和new \Think\Page()中的第三个参数一致，上面有
	var page_url = "<?php echo U('Admin/Resources/get_page')?>"; 
    var url = "<?php echo U('Admin/Resources/resource_library',array('is_ajax'=>'1'))?>"; // 这里自己写ajax的url
    var show_type = "<?php echo $show_type;?>";
    var chosed_resource_ids = $("input[name='chosed_resource_ids']").val();
    var type="<?php echo $type;?>";
    $.get(page_url, {
    	'p':id,
    	'show_type':show_type,
    	'chosed_resource_ids':chosed_resource_ids,
    	'Name':"<?php echo $formParam['Name'];?>",
    	'startDate':"<?php echo $formParam['startDate'];?>",
    	'endDate':"<?php echo $formParam['endDate'];?>",
    	'type':"<?php echo $formParam['type'];?>",
    	'desc':"<?php echo $formParam['desc'];?>"
    }, function(page_data){    // 用get方法发送信息到url里
        $("#page_show").html(page_data); // 将数据返回
    });
    
    $.get(url, {
    	'p':id,
    	'show_type':show_type,
    	'chosed_resource_ids':chosed_resource_ids,
    	'Name':"<?php echo $formParam['Name'];?>",
    	'startDate':"<?php echo $formParam['startDate'];?>",
    	'endDate':"<?php echo $formParam['endDate'];?>",
    	'type':"<?php echo $formParam['type'];?>",
    	'desc':"<?php echo $formParam['desc'];?>"
    }, function(data){    // 用get方法发送信息到url里
        $("#ajax_show").html(data); // 将数据返回
    });
 }

function setUpload(fileName, fileSize){
    $("#fileName").val(fileName);
    $("#fileSize").val(fileSize);
    $("#upload_file_name_show").html(fileName);
}  

    
function open_upload(){
	  layer.open({
	    type: 2,
	    //skin: 'layui-layer-lan',
	    title: '上传视频',
	    fix: false,
	    shadeClose: true,
	    maxmin: true,
	    area: ['1000px', '500px'],
	    content: "<?php echo U('Admin/NewsVideo/open_upload')?>",
	    end: function(){
	    }
	  });
}

    $(document).ready(function () {
        $('#channelId').change(function () {
            $.get('{:U("Admin/News/ajax_get_subject")}' + '&cateId=' + $('#channelId').val(), function (data) {
                var html = '<option value="0">--无--</option>';
                if(data['state']=="success"){
                    html = '<option value="-1">全部</option>';
                    for (var a in data.tagList) {
                        html += '<option value="' + data.tagList[a].tagTitle + '">' + data.tagList[a].tagTitle + '</option>';
                    }
                }
                $('#subjectId').html(html);
            });
        });
    });
    function html5Reader(file, previewId){
        var file = file.files[0];
        var reader = new FileReader();
        reader.readAsDataURL(file);
        reader.onload = function(e){
            $('#'+previewId).attr('src', this.result);
        }
    }
    function image_change(fileId, previewId) {
        var pic = document.getElementById(previewId),
                file = document.getElementById(fileId);

        var ext = file.value.substring(file.value.lastIndexOf(".")+1).toLowerCase();

        // gif在IE浏览器暂时无法显示
        if(ext != 'png' && ext != 'jpg' && ext != 'jpeg'){
            alert("图片的格式必须为png或者jpg或者jpeg格式！");
            return;
        }
        var isIE = navigator.userAgent.match(/MSIE/)!= null,
                isIE6 = navigator.userAgent.match(/MSIE 6.0/)!= null;

        if(isIE) {
            file.select();
            var realLocalPath = document.selection.createRange().text;

            // IE6浏览器设置img的src为本地路径可以直接显示图片
            if (isIE6) {
                pic.src = realLocalPath;
            }else {
                // 非IE6版本的IE由于安全问题直接设置img的src无法显示本地图片，但是可以通过滤镜来实现
                pic.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod='image',src=\"" + realLocalPath + "\")";
                // 设置img的src为base64编码的透明图片 取消显示浏览器默认图片
                pic.src = '';
            }
        }else {
            html5Reader(file, previewId);
        }
    }

    $("#picker").click(function(){
        $("#imageFile").click();
    });

    $("#imageFile").change(function(){
        image_change('imageFile', 'imagePreview');
    });
</script>
<script src="__PUBLIC__/js/common.js"></script>
<script src="__PUBLIC__/js/layer/layer.js"></script>
<script src="__PUBLIC__/js/publish.js"></script>
<script type="text/javascript" src="__PUBLIC__/js/content_addtop.js"></script>
<script type="text/javascript" src="__PUBLIC__/js/ueditor/ueditor.config.js"></script>
<script type="text/javascript" src="__PUBLIC__/js/ueditor/ueditor.all.min.js"></script>
<script>
    $(document).ready(function () {
        $('input[name="query_form_btn"]').click(function () {
            $('#query_form').attr('action', $(this).attr('data-action'));
            $('#query_form').submit();
        });
    });
   
  //打开添加资源页面
 function add_resource(show_type){
	 if(show_type  == '2'){
		 var set_water= "<?php echo $set_water;?>";
		 var chosed_resource_ids = $("input[name='chosed_resource_ids']").val();
		 var call_back = $("#call_back").val();
		 window.location.href="<?php echo U('Admin/Resources/add_resource')?>"+"&show_type=2&set_water="+set_water+"&chosed_resource_ids="+chosed_resource_ids+"&type="+"<?php echo $formParam['type'];?>"+"&call_back="+call_back;
	 }else{
		  layer.open({
		  	    type: 2,
		  	    //skin: 'layui-layer-lan',
		  	    title: '添加资源',
		  	    fix: false,
		  	    shadeClose: true,
		  	    maxmin: true,
		  	    area: ['1000px', '500px'],
		  	    content: "<?php echo U('Admin/Resources/add_resource')?>",
		  	    end: function(){
		  	    	location.reload();
		  	    }
		  	  });
	 }

 }
 
 function data_sort(order_val){
	 $(".order").val(order_val);
	 $("#data_form").submit();
 }
 
 document.domain = "<?php echo C('domain');?>";
 function set_resource(resource_id,type){
	 if(type== '1'){
		 var img_name = $("#file_name_"+resource_id).val();
		 var img_url = $("#thumbnail_url_"+resource_id).val();
		 if(img_name && img_url){
			 setImages(img_name,img_url,resource_id); 
		 }else{
			 $("#checkbox_"+resource_id).attr("checked",false);
			 layer.msg('资源参数缺失,请联系管理员!');
			 return false;
		 }
		 
		 //parent.setImages(img_name,img_url,resource_id); 
	 }
	 if(type== '2'){
		 var video_name = $("#file_name_"+resource_id).val();
		 var video_url = $("#url_"+resource_id).val();
		 var video_file_id = $("#file_id_"+resource_id).val();
		 var video_duration = $("#duration_"+resource_id).val();
		 var video_height = $("#height_"+resource_id).val();
		 var video_width = $("#width_"+resource_id).val();
		 var video_size = $("#size_"+resource_id).val();
		 
		 if(!video_url){
			 video_url = $("#url1_"+resource_id).val();
			 video_height = $("#height1_"+resource_id).val();
			 video_width = $("#width1_"+resource_id).val();
			 video_size = $("#size1_"+resource_id).val();
		 }
		 if(!video_url){
			 video_url = $("#url2_"+resource_id).val();
			 video_height = $("#height2_"+resource_id).val();
			 video_width = $("#width2_"+resource_id).val();
			 video_size = $("#size2_"+resource_id).val();
		 }
		 var thumbnail_url = $("#thumbnail_url_"+resource_id).val();
		 if(video_name && video_url && thumbnail_url && video_file_id && video_height && video_width && video_size){
			 setVideos(video_name, video_url, resource_id, thumbnail_url,video_file_id,video_duration,video_height,video_width,video_size); 
		 }else{
			 $("#checkbox_"+resource_id).attr("checked",false);
			 layer.msg('资源参数缺失,请联系管理员!');
			 return false;
		 }
		 //parent.setVideos(video_name, video_url, resource_id, thumbnail_url); 
	 }
	 
		var chosed_ids = $("input[name='chosed_resource_ids']").val();
		old_chosed_ids_arr = chosed_ids.split(',');  //原始数组
		if(old_chosed_ids_arr.indexOf(resource_id) != '-1'){
			$.each(old_chosed_ids_arr,function(index,item){  
	            // index是索引值（即下标）   item是每次遍历得到的值；
	            if(item==resource_id){
	            	old_chosed_ids_arr.splice(index,1);
	        	}
	     	});
			chosed_ids = old_chosed_ids_arr.join(",");
		}else{
			chosed_ids+=resource_id+',';
		}
		chosed_ids_arr = chosed_ids.split(',');
		chosed_ids_arr.pop();		
		$("input[name='chosed_resource_ids']").val(chosed_ids);
		window.localStorage.setItem('chosed_resource_ids',chosed_ids);
		
 }

	function setImages(img_name, img_url,resource_id){
		var chosed_img_ids = $("#chosed_img_ids").val();
		var chosed_img_names = $("#chosed_img_names").val();
		var chosed_img_urls = $("#chosed_img_urls").val();

		old_chosed_img_ids_arr = chosed_img_ids.split(',');  //原始数组
		old_chosed_img_names_arr = chosed_img_names.split(',');  //原始数组
		old_chosed_img_urls_arr = chosed_img_urls.split('~');  //原始数组

		if(old_chosed_img_ids_arr.indexOf(resource_id) != '-1'){
			$.each(old_chosed_img_ids_arr,function(index,item){  
	            // index是索引值（即下标）   item是每次遍历得到的值；
	            if(item==resource_id){
	            	old_chosed_img_ids_arr.splice(index,1);
	            	old_chosed_img_names_arr.splice(index,1);
	            	old_chosed_img_urls_arr.splice(index,1);
	            	//取消打钩
	            	$("#checkbox_"+resource_id).attr("checked",false);
	        	}
	     	});
			chosed_img_ids = old_chosed_img_ids_arr.join(",");
			chosed_img_names = old_chosed_img_names_arr.join(",");
			chosed_img_urls = old_chosed_img_urls_arr.join("~");
		}else{
			chosed_img_ids+=resource_id+',';
			chosed_img_names+=img_name+',';
			chosed_img_urls+=img_url+'~';
		}

		chosed_img_ids_arr = chosed_img_ids.split(',');
		chosed_img_ids_arr.pop();
		chosed_img_names_arr = chosed_img_names.split(',');
		chosed_img_names_arr.pop();
		chosed_img_urls_arr = chosed_img_urls.split('~');
		chosed_img_urls_arr.pop();
		
		var show_img_html = '';
		for (var i=0;i<chosed_img_ids_arr.length;i++)
		{
			show_img_html +='<li><img src="'+chosed_img_urls_arr[i]+'" alt="" /><span><a href="javascript:;" onclick="DelImages('+"'"+chosed_img_ids_arr[i]+"'"+')" class="del_btn">删除</a></span></li>';
		}
		$("#upload_img_show").html(show_img_html);
		$("#chosed_img_ids").val(chosed_img_ids);
		$("#chosed_img_names").val(chosed_img_names);
		$("#chosed_img_urls").val(chosed_img_urls);

		window.localStorage.setItem('chosed_img_ids',chosed_img_ids);
		window.localStorage.setItem('chosed_img_names',chosed_img_names);
		window.localStorage.setItem('chosed_img_urls',chosed_img_urls);
	}
	
	//删除选中图片
	function DelImages(resource_id){
		var chosed_img_ids = $("#chosed_img_ids").val();
		var chosed_img_names = $("#chosed_img_names").val();
		var chosed_img_urls = $("#chosed_img_urls").val();

		old_chosed_img_ids_arr = chosed_img_ids.split(',');  //原始数组
		old_chosed_img_names_arr = chosed_img_names.split(',');  //原始数组
		old_chosed_img_urls_arr = chosed_img_urls.split('~');  //原始数组

		if(old_chosed_img_ids_arr.indexOf(resource_id) != '-1'){
			$.each(old_chosed_img_ids_arr,function(index,item){  
	            // index是索引值（即下标）   item是每次遍历得到的值；
	            if(item==resource_id){
	            	old_chosed_img_ids_arr.splice(index,1);
	            	old_chosed_img_names_arr.splice(index,1);
	            	old_chosed_img_urls_arr.splice(index,1);
	            	//取消打钩
	            	$("#checkbox_"+resource_id).attr("checked",false);
	        	}
	     	});
			chosed_img_ids = old_chosed_img_ids_arr.join(",");
			chosed_img_names = old_chosed_img_names_arr.join(",");
			chosed_img_urls = old_chosed_img_urls_arr.join("~");
		}else{
			layer.msg('参数缺失,请联系管理员!');
			return false;
		}

		chosed_img_ids_arr = chosed_img_ids.split(',');
		chosed_img_ids_arr.pop();
		chosed_img_names_arr = chosed_img_names.split(',');
		chosed_img_names_arr.pop();
		chosed_img_urls_arr = chosed_img_urls.split('~');
		chosed_img_urls_arr.pop();
		
		var show_img_html = '';
		for (var i=0;i<chosed_img_ids_arr.length;i++)
		{
			show_img_html +='<li><img src="'+chosed_img_urls_arr[i]+'" alt="" /><span><a href="javascript:;" onclick="DelImages('+"'"+chosed_img_ids_arr[i]+"'"+')" class="del_btn">删除</a></span></li>';
		}
		$("#upload_img_show").html(show_img_html);
		$("#chosed_img_ids").val(chosed_img_ids);
		$("#chosed_img_names").val(chosed_img_names);
		$("#chosed_img_urls").val(chosed_img_urls);
		$("input[name='chosed_resource_ids']").val(chosed_img_ids);
		
		window.localStorage.setItem('chosed_img_ids',chosed_img_ids);
		window.localStorage.setItem('chosed_img_names',chosed_img_names);
		window.localStorage.setItem('chosed_img_urls',chosed_img_urls);
		window.localStorage.setItem('chosed_resource_ids',chosed_img_ids);
	}
	
	
	function setVideos(video_name, video_url, resource_id, thumbnail_url, file_id, duration, height, width, size){
		var chosed_video_ids = $("#chosed_video_ids").val();
		var chosed_video_names = $("#chosed_video_names").val();
		var chosed_video_urls = $("#chosed_video_urls").val();
		var chosed_video_thumbnail_urls = $("#chosed_video_thumbnail_urls").val();
		var chosed_video_file_ids = $("#chosed_video_file_ids").val();
		var chosed_video_durations = $("#chosed_video_durations").val();
		var chosed_video_heights = $("#chosed_video_heights").val();
		var chosed_video_widths = $("#chosed_video_widths").val();
		var chosed_video_sizes = $("#chosed_video_sizes").val();
		
		old_chosed_video_ids_arr = chosed_video_ids.split(',');  //原始数组
		old_chosed_video_names_arr = chosed_video_names.split(',');  //原始数组
		old_chosed_video_urls_arr = chosed_video_urls.split('~');  //原始数组
		old_chosed_video_thumbnail_urls_arr = chosed_video_thumbnail_urls.split('~');  //原始数组
		old_chosed_video_file_ids_arr = chosed_video_file_ids.split(',');  //原始数组
		old_chosed_video_durations_arr = chosed_video_durations.split(',');  //原始数组
		old_chosed_video_heights_arr = chosed_video_heights.split(',');  //原始数组
		old_chosed_video_widths_arr = chosed_video_widths.split(',');  //原始数组
		old_chosed_video_sizes_arr = chosed_video_sizes.split(',');  //原始数组
		
		if(old_chosed_video_ids_arr.indexOf(resource_id) != '-1'){
			$.each(old_chosed_video_ids_arr,function(index,item){  
	            // index是索引值（即下标）   item是每次遍历得到的值；
	            if(item==resource_id){
	            	old_chosed_video_ids_arr.splice(index,1);
	            	old_chosed_video_names_arr.splice(index,1);
	            	old_chosed_video_urls_arr.splice(index,1);
	            	old_chosed_video_thumbnail_urls_arr.splice(index,1);
	            	old_chosed_video_file_ids_arr.splice(index,1);
	            	old_chosed_video_durations_arr.splice(index,1);
	            	old_chosed_video_heights_arr.splice(index,1);
	            	old_chosed_video_widths_arr.splice(index,1);
	            	old_chosed_video_sizes_arr.splice(index,1);
	            	//取消打钩
	            	$("#checkbox_"+resource_id).attr("checked",false);
	        	}
	     	});
			chosed_video_ids = old_chosed_video_ids_arr.join(",");
			chosed_video_names = old_chosed_video_names_arr.join(",");
			chosed_video_urls = old_chosed_video_urls_arr.join("~");
			chosed_video_thumbnail_urls = old_chosed_video_thumbnail_urls_arr.join("~");
			chosed_video_file_ids = old_chosed_video_file_ids_arr.join(",");
			chosed_video_durations = old_chosed_video_durations_arr.join(",");
			chosed_video_heights = old_chosed_video_heights_arr.join(",");
			chosed_video_widths = old_chosed_video_widths_arr.join(",");
			chosed_video_sizes = old_chosed_video_sizes_arr.join(",");
		}else{
			chosed_video_ids+=resource_id+',';
			chosed_video_names+=video_name+',';
			chosed_video_urls+=video_url+'~';
			chosed_video_thumbnail_urls+=thumbnail_url+'~';
			chosed_video_file_ids+=file_id+',';
			chosed_video_durations+=duration+',';
			chosed_video_heights+=height+',';
			chosed_video_widths+=width+',';
			chosed_video_sizes+=size+',';
		}
		chosed_video_ids_arr = chosed_video_ids.split(',');
		chosed_video_ids_arr.pop();
		chosed_video_names_arr = chosed_video_names.split(',');
		chosed_video_names_arr.pop();
		chosed_video_urls_arr = chosed_video_urls.split('~');
		chosed_video_urls_arr.pop();
		chosed_video_thumbnail_urls_arr = chosed_video_thumbnail_urls.split('~');
		chosed_video_thumbnail_urls_arr.pop();
		chosed_video_file_ids_arr = chosed_video_file_ids.split(',');
		chosed_video_file_ids_arr.pop();
		chosed_video_durations_arr = chosed_video_durations.split(',');
		chosed_video_durations_arr.pop();
		chosed_video_heights_arr = chosed_video_heights.split(',');
		chosed_video_heights_arr.pop();
		chosed_video_widths_arr = chosed_video_widths.split(',');
		chosed_video_widths_arr.pop();
		chosed_video_sizes_arr = chosed_video_sizes.split(',');
		chosed_video_sizes_arr.pop();
		
		var show_html = '';
		for (var i=1;i<=chosed_video_ids_arr.length;i++)
		{
			show_html +='<div style="margin-bottom:15px"><span><img src="'+chosed_video_thumbnail_urls_arr[parseInt(i) - 1]+'" alt=""  style="width:100px; height:60px;" /></br>'+i+'.视频名称:'+chosed_video_names_arr[parseInt(i) - 1]+'</span><a href="javascript:;" onclick="DelVideos('+"'"+chosed_video_ids_arr[parseInt(i) - 1]+"'"+')" class="del_btn">删除</a></br></div>';
		}
		$("#chose_video_show").html(show_html);
		$("#chosed_video_ids").val(chosed_video_ids);
		$("#chosed_video_names").val(chosed_video_names);
		$("#chosed_video_urls").val(chosed_video_urls);
		$("#chosed_video_thumbnail_urls").val(chosed_video_thumbnail_urls);
		$("#chosed_video_file_ids").val(chosed_video_file_ids);
		$("#chosed_video_durations").val(chosed_video_durations);
		$("#chosed_video_heights").val(chosed_video_heights);
		$("#chosed_video_widths").val(chosed_video_widths);
		$("#chosed_video_sizes").val(chosed_video_sizes);
	}
	
	
	//删除选中视频
	function DelVideos(resource_id){
		var chosed_video_ids = $("#chosed_video_ids").val();
		var chosed_video_names = $("#chosed_video_names").val();
		var chosed_video_urls = $("#chosed_video_urls").val();
		var chosed_video_thumbnail_urls = $("#chosed_video_thumbnail_urls").val();
		var chosed_video_file_ids = $("#chosed_video_file_ids").val();
		var chosed_video_durations = $("#chosed_video_durations").val();
		var chosed_video_heights = $("#chosed_video_heights").val();
		var chosed_video_widths = $("#chosed_video_widths").val();
		var chosed_video_sizes = $("#chosed_video_sizes").val();
		
		old_chosed_video_ids_arr = chosed_video_ids.split(',');  //原始数组
		old_chosed_video_names_arr = chosed_video_names.split(',');  //原始数组
		old_chosed_video_urls_arr = chosed_video_urls.split('~');  //原始数组
		old_chosed_video_thumbnail_urls_arr = chosed_video_thumbnail_urls.split('~');  //原始数组
		old_chosed_video_file_ids_arr = chosed_video_file_ids.split(',');  //原始数组
		old_chosed_video_durations_arr = chosed_video_durations.split(',');  //原始数组
		old_chosed_video_heights_arr = chosed_video_heights.split(',');  //原始数组
		old_chosed_video_widths_arr = chosed_video_widths.split(',');  //原始数组
		old_chosed_video_sizes_arr = chosed_video_sizes.split(',');  //原始数组
		
		if(old_chosed_video_ids_arr.indexOf(resource_id) != '-1'){
			$.each(old_chosed_video_ids_arr,function(index,item){  
	            // index是索引值（即下标）   item是每次遍历得到的值；
	            if(item==resource_id){
	            	old_chosed_video_ids_arr.splice(index,1);
	            	old_chosed_video_names_arr.splice(index,1);
	            	old_chosed_video_urls_arr.splice(index,1);
	            	old_chosed_video_thumbnail_urls_arr.splice(index,1);
	            	old_chosed_video_file_ids_arr.splice(index,1);
	            	old_chosed_video_durations_arr.splice(index,1);
	            	old_chosed_video_heights_arr.splice(index,1);
	            	old_chosed_video_widths_arr.splice(index,1);
	            	old_chosed_video_sizes_arr.splice(index,1);
	            	//取消打钩
	            	$("#checkbox_"+resource_id).attr("checked",false);
	        	}
	     	});
			chosed_video_ids = old_chosed_video_ids_arr.join(",");
			chosed_video_names = old_chosed_video_names_arr.join(",");
			chosed_video_urls = old_chosed_video_urls_arr.join("~");
			chosed_video_thumbnail_urls = old_chosed_video_thumbnail_urls_arr.join("~");
			chosed_video_file_ids = old_chosed_video_file_ids_arr.join(",");
			chosed_video_durations = old_chosed_video_durations_arr.join(",");
			chosed_video_heights = old_chosed_video_heights_arr.join(",");
			chosed_video_widths = old_chosed_video_widths_arr.join(",");
			chosed_video_sizes = old_chosed_video_sizes_arr.join(",");
		}else{
			layer.msg('参数缺失,请联系管理员!');
			return false;
		}
		chosed_video_ids_arr = chosed_video_ids.split(',');
		chosed_video_ids_arr.pop();
		chosed_video_names_arr = chosed_video_names.split(',');
		chosed_video_names_arr.pop();
		chosed_video_urls_arr = chosed_video_urls.split('~');
		chosed_video_urls_arr.pop();
		chosed_video_thumbnail_urls_arr = chosed_video_thumbnail_urls.split('~');
		chosed_video_thumbnail_urls_arr.pop();
		chosed_video_file_ids_arr = chosed_video_file_ids.split(',');
		chosed_video_file_ids_arr.pop();
		chosed_video_durations_arr = chosed_video_durations.split(',');
		chosed_video_durations_arr.pop();
		chosed_video_heights_arr = chosed_video_heights.split(',');
		chosed_video_heights_arr.pop();
		chosed_video_widths_arr = chosed_video_widths.split(',');
		chosed_video_widths_arr.pop();
		chosed_video_sizes_arr = chosed_video_sizes.split(',');
		chosed_video_sizes_arr.pop();
		
		var show_html = '';
		for (var i=1;i<=chosed_video_ids_arr.length;i++)
		{
			show_html +='<div style="margin-bottom:15px"><span><img src="'+chosed_video_thumbnail_urls_arr[parseInt(i) - 1]+'" alt=""  style="width:100px; height:60px;" /></br>'+i+'.视频名称:'+chosed_video_names_arr[parseInt(i) - 1]+'</span><a href="javascript:;" onclick="DelVideos('+"'"+chosed_video_ids_arr[parseInt(i) - 1]+"'"+')" class="del_btn">删除</a></br></div>';
		}
		$("#chose_video_show").html(show_html);
		$("#chosed_video_ids").val(chosed_video_ids);
		$("#chosed_video_names").val(chosed_video_names);
		$("#chosed_video_urls").val(chosed_video_urls);
		$("#chosed_video_thumbnail_urls").val(chosed_video_thumbnail_urls);
		$("#chosed_video_file_ids").val(chosed_video_file_ids);
		$("#chosed_video_durations").val(chosed_video_durations);
		$("#chosed_video_heights").val(chosed_video_heights);
		$("#chosed_video_widths").val(chosed_video_widths);
		$("#chosed_video_sizes").val(chosed_video_sizes);
		$("input[name='chosed_resource_ids']").val(chosed_video_ids);
	}
	
</script>
<script type="text/javascript" >

function getFileDir(){
    return $("#fileDir").val();
}  
    

</script>
<script src="/public/simpleboot/themes/resources/resource.js?ver=1.0"></script>
</body>
</html>

